package com.yanqu.road.server.manager.tomb.event;

import com.yanqu.road.logic.activity.tomb.config.entity.ActivityTombFloor;
import com.yanqu.road.pb.tomb.Tomb;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.tomb.Position;
import com.yanqu.road.server.manager.tomb.TombMaze;
import com.yanqu.road.logic.activity.tomb.config.entity.ActivityTombEvent;
import com.yanqu.road.server.manager.tomb.entity.*;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.time.Instant;

public class PvpBattle implements IEvent {

    @Override
    public boolean canStand(DbTombUser dbTombUser, TombMaze tombMaze, Position position) {
        return true;
    }

    @Override
    public boolean canThrough(DbTombUser dbTombUser, TombMaze tombMaze, Position position) {
        return true;
    }

    @Override
    public boolean canExplore(DbTombUser dbTombUser, TombMaze tombMaze, Position position) {
        return false;
    }

    @Override
    public void detail(TombMaze tombMaze, DbTombUser dbTombUser, Position position, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventExploreResp.Builder builder) {
        DbTombPosition dbTombPosition = tombMaze.getDbTombPosition(position.getKey());
        if (dbTombPosition == null) {
            return;
        }
        if (!dbTombPosition.containUnionDig(dbTombUser.getUserInfo().getUnionUid())) {
            return;
        }
        ActivityTombEvent activityTombEvent = tombMaze.getConfig().getEvent(dbTombPosition.getEventId());
        long unionDigUser = dbTombPosition.acquireUnionDigUser(dbTombUser.getUserInfo().getUnionUid());
        DbTombUser digDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(unionDigUser);
        positionTempBuilder.setDigUser(digDbTombUser.toEventUserInfoBuilder());
        positionTempBuilder.setEventConfig(activityTombEvent.getEventConfigBuilder());
        positionTempBuilder.setAttackTimes(dbTombPosition.getAttackTimes(dbTombUser.getUserId()));
        String key = String.format("%d_%d_%d_%d", dbTombUser.getGroupId(), tombMaze.getFloor(), position.getRow(), position.getColumn());
        builder.addAllEventUserInfo(tombMaze.getEventUserInfoList(dbTombUser, key));

        DbTombUser pvpDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(dbTombPosition.getPvpUserId());
        positionTempBuilder.setAttackInfo(pvpDbTombUser.toPvpUserInfoTempBuilder());
        positionTempBuilder.setHp(pvpDbTombUser.getHp());
        positionTempBuilder.setMaxHp(pvpDbTombUser.getMaxHp());
        positionTempBuilder.setEnum(position.getpEnum());
        positionTempBuilder.setEventEnum(position.geteType());

        PositionInfo positionInfo = dbTombPosition.acquireEventInfo(dbTombUser.getUserId());
        positionTempBuilder.setLastAttackTimestamp(positionInfo.getTimestamp() * 1000);
        positionTempBuilder.setOverTime(dbTombPosition.getCreateTime() + 10*1000);

    }

    @Override
    public void explore(TombMaze tombMaze, DbTombUser dbTombUser, DbTombPosition dbTombPosition, Position position, ActivityTombEvent activityTombEvent, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventExploreResp.Builder builder) {
        DbTombUser pvpDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(dbTombPosition.getPvpUserId());
        positionTempBuilder.setAttackInfo(pvpDbTombUser.toPvpUserInfoTempBuilder());
        pvpDbTombUser.getPvpUnionChooseMap().add(dbTombUser.getUserInfo().getUnionUid());
        dbTombPosition.setStatus(1);
        dbTombPosition.refreshUpdateTime();

        positionTempBuilder.setMaxHp(pvpDbTombUser.getMaxHp());
        positionTempBuilder.setHp(pvpDbTombUser.getHp());

        positionTempBuilder.setEnum(position.getpEnum());
        positionTempBuilder.setEventEnum(position.geteType());

        positionTempBuilder.setLastAttackTimestamp(0);

        PositionInfo positionInfo = dbTombPosition.acquireEventInfo(dbTombUser.getUserId());
        positionTempBuilder.setLastAttackTimestamp(positionInfo.getTimestamp() * 1000);
        positionTempBuilder.setOverTime(dbTombPosition.getCreateTime() + 10*1000);

    }

    public void display(DbTombUser dbTombUser, TombMaze tombMaze, Position position, Tomb.PositionTemp.Builder p) {
        DbTombPosition dbTombPosition = tombMaze.getDbTombPosition(position.getKey());
        if (dbTombPosition == null) {
            p.setIsOver(true);
            return;
        }
        DbTombUser pvpDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(dbTombPosition.getPvpUserId());
        if (!pvpDbTombUser.isAlive()) {
            p.setIsOver(true);
            return;
        }
        if (!dbTombPosition.containUnionDig(dbTombUser.getUserInfo().getUnionUid())) {
            p.setIsOver(true);
            return;
        }

        p.setMaxHp(pvpDbTombUser.getMaxHp());
        p.setHp(pvpDbTombUser.getHp());
        p.setAttackInfo(pvpDbTombUser.toPvpUserInfoTempBuilder());
        ActivityTombEvent event = tombMaze.getConfig().getEvent(dbTombPosition.getEventId());
        p.setEventConfig(event.getEventConfigBuilder());
        p.setIsOver(false);
    }


    @Override
    public void info(TombMaze tombMaze, DbTombUser dbTombUser, DbTombPosition dbTombPosition, Position position, ActivityTombEvent activityTombEvent, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventInfoResp.Builder builder) {
        if (!dbTombPosition.containUnionDig(dbTombUser.getUserInfo().getUnionUid())) {
            return;
        }
        long unionDigUser = dbTombPosition.acquireUnionDigUser(dbTombUser.getUserInfo().getUnionUid());
        DbTombUser digDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(unionDigUser);
        positionTempBuilder.setDigUser(digDbTombUser.toEventUserInfoBuilder());
        positionTempBuilder.setEventConfig(activityTombEvent.getEventConfigBuilder());
        positionTempBuilder.setAttackTimes(dbTombPosition.getAttackTimes(dbTombUser.getUserId()));
        String key = String.format("%d_%d_%d_%d", dbTombUser.getGroupId(), tombMaze.getFloor(), position.getRow(), position.getColumn());
        builder.addAllEventUserInfo(tombMaze.getEventUserInfoList(dbTombUser, key));

        DbTombUser pvpDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(dbTombPosition.getPvpUserId());
        positionTempBuilder.setAttackInfo(pvpDbTombUser.toPvpUserInfoTempBuilder());
        positionTempBuilder.setHp(pvpDbTombUser.getHp());
        positionTempBuilder.setMaxHp(pvpDbTombUser.getMaxHp());

        PositionInfo positionInfo = dbTombPosition.acquireEventInfo(dbTombUser.getUserId());
        positionTempBuilder.setLastAttackTimestamp(positionInfo.getTimestamp() * 1000);
        positionTempBuilder.setOverTime(dbTombPosition.getCreateTime() + 10*1000);
    }

    @Override
    public void touch(TombMaze tombMaze, DbTombUser dbTombUser, DbTombPosition dbTombPosition, Position position, ActivityTombEvent activityTombEvent, Tomb.PositionTemp.Builder positionTempBuilder, Tomb.TombEventTouchResp.Builder builder, Tomb.TombEventTouchReq req) {

        if (dbTombPosition.getDone() == 1) {
            builder.setRet(GameErrorCode.E_TOMB_TARGET_IS_NOT_ALIVE);
            return;
        }

        if (dbTombUser.getUserId() != dbTombPosition.acquireDigUser()) {
            if (System.currentTimeMillis() < dbTombPosition.getCreateTime() + 10*1000){
                builder.setRet(GameErrorCode.E_TOMB_BATTLE_EVENT_PROTECT_TIME);
                return;
            }
        }

        if (!dbTombPosition.containUnionDig(dbTombUser.getUserInfo().getUnionUid())) {
            builder.setRet(GameErrorCode.E_TOMB_EVENT_NOT_DIG);
            return;
        }
        DbTombUser pvpDbTombUser = tombMaze.getActivity().getDbData().getDbTombUser(dbTombPosition.getPvpUserId());
        if (pvpDbTombUser == null) {
            builder.setRet(GameErrorCode.E_TOMB_USER_NOT_FOUND);
            return;
        }

        synchronized (pvpDbTombUser.getPartnerUpgradeInfoMap()) {
            if (!pvpDbTombUser.isAlive()) {
                builder.setRet(GameErrorCode.E_TOMB_TARGET_IS_NOT_ALIVE);
                return;
            }

            PositionInfo positionInfo = dbTombPosition.getEventInfoMap().get(dbTombUser.getUserId());
            if (positionInfo != null) {
                if (positionInfo.getTimestamp() + tombMaze.getConfig().getConfig().getTOMB_PVP_COOL_DOWN_CD() > Instant.now().getEpochSecond()) {
                    builder.setRet(GameErrorCode.E_TOMB_EVENT_UN_COLD_DOWN);
                    return;
                }
            }

            /**
             * 这里检查是否有足够的协助次数
             */
            if (dbTombPosition.acquireDigUser() != dbTombUser.getUserId()) {
                if (!tombMaze.checkIsEnoughAssistTimes(dbTombUser, 1)) {
                    builder.setRet(GameErrorCode.E_TOMB_NOT_ENOUGH_ASSIST_TIMES);
                    return;
                }
            }

            long costEnergy = 0;
            if (tombMaze.checkPVPNeedCostEnergy(pvpDbTombUser, dbTombPosition, dbTombUser)) {
                boolean b = tombMaze.costEnergy(dbTombUser, 0, activityTombEvent.getId());
                if (!b) {
                    builder.setRet(GameErrorCode.E_TOMB_USER_NOT_ENOUGH_ENERGY);
                    return;
                }
                /**
                 * 这里扣除协助次数
                 */
                if (dbTombPosition.acquireDigUser() != dbTombUser.getUserId()) {
                    if (!tombMaze.costAssistTimes(dbTombUser, 1)) {
                        builder.setRet(GameErrorCode.E_TOMB_NOT_ENOUGH_ASSIST_TIMES);
                        return;
                    }
                }
                ActivityTombFloor activityTombFloor = tombMaze.getActivity().getConfig().getFloor(tombMaze.getFloor());
                costEnergy = activityTombFloor.getEnergy();
            }

            long attack = dbTombUser.getTotalAttack();
            attack = pvpDbTombUser.underAttack(attack);
            boolean alive = pvpDbTombUser.isAlive();
            if (attack > 0) {
                dbTombPosition.addEventInfo(dbTombUser.getUserId(), dbTombUser.getUserInfo().getNickName(), attack);
            }
            Property property = null;

            boolean isKilled = false;

            if (alive) {
                property = new Property();
            } else if (attack > 0) {
                isKilled = true;

                dbTombPosition.setFinishUserId(dbTombUser.getUserId());
                position.setKillUserId(dbTombUser.getUserId());

                property = new Property(activityTombEvent.getReward());
                Property randMonsterReward = activityTombEvent.randMonsterReward();
                property.addProperty(randMonsterReward);

                dbTombUser.addMultiKill(1);
                int rewardScore = dbTombUser.getMultiKill() * tombMaze.getActivity().getConfig().getConfig().getTOMB_PVP_GUILD_SCORE_BASE();
                dbTombUser.setRewardScore(rewardScore);

                int unionScore = -tombMaze.getConfig().getConfig().getTOMB_PVP_GUILD_SCORE_KILLED();
                pvpDbTombUser.addUnionScore(unionScore);


                //发到游戏服写日志
                Tomb.TombLogCrossToGameReq.Builder logBuilder = Tomb.TombLogCrossToGameReq.newBuilder();
                logBuilder.setLEnum(Tomb.GameTombLogEnum.SCORE);
                logBuilder.setUserId(dbTombUser.getUserId());
                logBuilder.setActivityId(tombMaze.getActivityId());
                logBuilder.setUnionUid(dbTombUser.getUserInfo().getUnionUid());
                logBuilder.setFloor(dbTombUser.getFloor());
                logBuilder.setX(position.getRow());
                logBuilder.setY(position.getColumn());
                logBuilder.setHp(dbTombUser.getHp());
                logBuilder.setTimestamp(System.currentTimeMillis());
                Tomb.TombLogScore.Builder score = Tomb.TombLogScore.newBuilder();
                score.setType(2);
                score.setScoreChange(unionScore);
                score.setScore(pvpDbTombUser.getUnionScore());
                logBuilder.setScore(score);

                tombMaze.getActivity().sendLogToGame(dbTombUser, logBuilder);


                //发送通知到游戏服去更新积分；
                Tomb.TombUserScoreChangeCrossToGameReq.Builder userScoreChangeBuilder = Tomb.TombUserScoreChangeCrossToGameReq.newBuilder();
                userScoreChangeBuilder.setUserId(pvpDbTombUser.getUserId());
                userScoreChangeBuilder.setUnionScore(pvpDbTombUser.getUnionScore());
                MessageHelper.sendToGameServer(pvpDbTombUser.getUserInfo().getServerId(), GameProtocol.S_TOMB_USER_SCORE_CHANGE_CROSS_TO_GAME, tombMaze.getActivityId(), dbTombUser.getUserId(), userScoreChangeBuilder, null);

                pvpDbTombUser.setStatus(2);

                property.addProperty(tombMaze.getActivity().getConfig().getConfig().getTOMB_GUILD_SCORE_ITEM_ID(), BigInteger.valueOf(pvpDbTombUser.getRewardScore()));
                pvpDbTombUser.setRewardScore(0);
                pvpDbTombUser.setMultiKill(0);

                pvpDbTombUser.setMaxHp(pvpDbTombUser.getTotalAttack());
                pvpDbTombUser.setAttackUserId(dbTombUser.getUserId());
                pvpDbTombUser.addPvpChoseNum(1);
                dbTombUser.addPvpChoseNum(-1);
                pvpDbTombUser.getPvpUnionChooseMap().remove(dbTombUser.getUserInfo().getUnionUid());
                pvpDbTombUser.refreshUpdateTime();
                tombMaze.eventDone(dbTombPosition, position);
            }

            builder.setValue(attack);
            positionTempBuilder.setAttackInfo(pvpDbTombUser.toPvpUserInfoTempBuilder());
            positionTempBuilder.setHp(pvpDbTombUser.getHp());
            positionTempBuilder.setMaxHp(pvpDbTombUser.getMaxHp());
            positionTempBuilder.setEventEnum(position.geteType());
            positionTempBuilder.setEnum(position.getpEnum());

            positionInfo = dbTombPosition.acquireEventInfo(dbTombUser.getUserId());
            positionTempBuilder.setLastAttackTimestamp(positionInfo.getTimestamp() * 1000);

            if (dbTombPosition.getFinishUserId() > 0) {
                DbTombUser dbTombUser1 = tombMaze.getActivity().getDbData().getDbTombUser(dbTombPosition.getFinishUserId());
                if (dbTombUser1 != null) {
                    positionTempBuilder.setFinishUser(dbTombUser1.toEventUserInfoBuilder());
                }
            }
            if (attack > 0) {
                tombMaze.attackPvpTombUserPush(dbTombUser, pvpDbTombUser, alive, attack, dbTombPosition, false);
                tombMaze.handleAttackScore(attack, pvpDbTombUser.getMaxHp(), activityTombEvent, property, dbTombUser);

                String key = String.format("%d_%d_%d_%d", dbTombUser.getGroupId(), tombMaze.getFloor(), position.getRow(), position.getColumn());
                tombMaze.eventBattleSyncPush(dbTombUser, attack, pvpDbTombUser.getHp(), key, false);

                Tomb.TombUserUnderAttackPush.Builder pushBuilder = Tomb.TombUserUnderAttackPush.newBuilder();
                pushBuilder.setUserId(pvpDbTombUser.getUserId());
                pushBuilder.setCurrentHp(pvpDbTombUser.getHp());
                pushBuilder.setMaxHp(pvpDbTombUser.getMaxHp());
                pushBuilder.setAlive(pvpDbTombUser.isAlive());
                pushBuilder.setAttackUser(dbTombUser.toEventUserInfoBuilder());
                pushBuilder.setUnionScore(pvpDbTombUser.getUnionScore());

                MessageHelper.sendToGameServer(pvpDbTombUser.getUserInfo().getServerId(), GameProtocol.S_TOMB_USER_UNDER_ATTACK_PUSH, tombMaze.getActivityId(), dbTombUser.getUserId(), pushBuilder, null);


                tombMaze.addProperty(property, dbTombUser);
                builder.setRewards(PropertyHelper.parsePropertyToString(property));
                //记日志

                if (isKilled) {
                    //日志
                    DbTombLog dbTombLog = DbTombLog.newInstance();
                    dbTombLog.setUid(String.valueOf(dbTombUser.getUserId()));
                    dbTombLog.setFloor(tombMaze.getFloor());
                    dbTombLog.setFromUserId(dbTombUser.getUserId());
                    dbTombLog.setToUserId(pvpDbTombUser.getUserId());
                    dbTombLog.setLogEnum(Tomb.TombLogEnum.TombLogEnum_Battle_VALUE);
                    dbTombLog.setEventId(activityTombEvent.getId());
                    dbTombLog.setValue(attack);
                    dbTombLog.setRewards(builder.getRewards());
                    dbTombLog.setEnergyChange(-activityTombEvent.getConsumeEnergy());
                    dbTombLog.setEnergy(dbTombUser.getEnergy(tombMaze.getConfig().getConfig()));
                    dbTombLog.setX(position.getRow());
                    dbTombLog.setY(position.getColumn());
                    dbTombLog.setDescription("杀死了其它玩家");
                    dbTombLog.setGroupId(dbTombUser.getGroupId());
                    dbTombLog.setStatus(1);
                    tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog, false);


                    //日志
                    DbTombLog dbTombLog1 = DbTombLog.newInstance();
                    dbTombLog1.setUid(String.valueOf(pvpDbTombUser.getUserId()));
                    dbTombLog1.setFloor(tombMaze.getFloor());
                    dbTombLog1.setFromUserId(dbTombUser.getUserId());
                    dbTombLog1.setToUserId(pvpDbTombUser.getUserId());
                    dbTombLog1.setLogEnum(Tomb.TombLogEnum.TombLogEnum_Battle_VALUE);
                    dbTombLog1.setEventId(activityTombEvent.getId());
                    dbTombLog1.setValue(attack);
                    dbTombLog1.setRewards(builder.getRewards());
                    dbTombLog1.setEnergyChange(-activityTombEvent.getConsumeEnergy());
                    dbTombLog1.setEnergy(dbTombUser.getEnergy(tombMaze.getConfig().getConfig()));
                    dbTombLog1.setX(position.getRow());
                    dbTombLog1.setY(position.getColumn());
                    dbTombLog1.setDescription("被其它玩家杀死了");
                    dbTombLog1.setGroupId(dbTombUser.getGroupId());
                    dbTombLog1.setStatus(1);
                    tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog1, false);


                    //日志
                    DbTombLog dbTombLog2 = DbTombLog.newInstance();
                    dbTombLog2.setUid(String.valueOf(tombMaze.getActivityId()));
                    dbTombLog2.setFloor(tombMaze.getFloor());
                    dbTombLog2.setFromUserId(dbTombUser.getUserId());
                    dbTombLog2.setToUserId(pvpDbTombUser.getUserId());
                    dbTombLog2.setLogEnum(Tomb.TombLogEnum.TombLogEnum_Battle_VALUE);
                    dbTombLog2.setEventId(activityTombEvent.getId());
                    dbTombLog2.setValue(attack);
                    dbTombLog2.setRewards(builder.getRewards());
                    dbTombLog2.setEnergyChange(-activityTombEvent.getConsumeEnergy());
                    dbTombLog2.setEnergy(dbTombUser.getEnergy(tombMaze.getConfig().getConfig()));
                    dbTombLog2.setX(position.getRow());
                    dbTombLog2.setY(position.getColumn());
                    dbTombLog2.setGroupId(dbTombUser.getGroupId());
                    dbTombLog2.setDescription("玩家杀死了玩家");
                    dbTombLog2.setStatus(1);
                    tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog2, true);
                } else {
                    //日志
                    DbTombLog dbTombLog = DbTombLog.newInstance();
                    dbTombLog.setUid(String.valueOf(dbTombUser.getUserId()));
                    dbTombLog.setFloor(tombMaze.getFloor());
                    dbTombLog.setFromUserId(dbTombUser.getUserId());
                    dbTombLog.setToUserId(pvpDbTombUser.getUserId());
                    dbTombLog.setLogEnum(Tomb.TombLogEnum.TombLogEnum_Battle_VALUE);
                    dbTombLog.setEventId(activityTombEvent.getId());
                    dbTombLog.setValue(attack);
                    dbTombLog.setRewards(builder.getRewards());
                    dbTombLog.setEnergyChange(-activityTombEvent.getConsumeEnergy());
                    dbTombLog.setEnergy(dbTombUser.getEnergy(tombMaze.getConfig().getConfig()));
                    dbTombLog.setX(position.getRow());
                    dbTombLog.setY(position.getColumn());
                    dbTombLog.setGroupId(dbTombUser.getGroupId());
                    dbTombLog.setDescription("攻击其它玩家");
                    tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog, false);


                    //日志
                    DbTombLog dbTombLog1 = DbTombLog.newInstance();
                    dbTombLog1.setUid(String.valueOf(pvpDbTombUser.getUserId()));
                    dbTombLog1.setFloor(tombMaze.getFloor());
                    dbTombLog1.setFromUserId(dbTombUser.getUserId());
                    dbTombLog1.setToUserId(pvpDbTombUser.getUserId());
                    dbTombLog1.setLogEnum(Tomb.TombLogEnum.TombLogEnum_Battle_VALUE);
                    dbTombLog1.setEventId(activityTombEvent.getId());
                    dbTombLog1.setValue(attack);
                    dbTombLog1.setRewards(builder.getRewards());
                    dbTombLog1.setEnergyChange(-activityTombEvent.getConsumeEnergy());
                    dbTombLog1.setEnergy(dbTombUser.getEnergy(tombMaze.getConfig().getConfig()));
                    dbTombLog1.setX(position.getRow());
                    dbTombLog1.setY(position.getColumn());
                    dbTombLog1.setGroupId(dbTombUser.getGroupId());
                    dbTombLog1.setDescription("被其它玩家攻击");
                    tombMaze.getActivity().getTombLog().addDbTombLog(dbTombLog1, false);
                }

                //发到游戏服写日志
                Tomb.TombLogCrossToGameReq.Builder logBuilder = Tomb.TombLogCrossToGameReq.newBuilder();
                logBuilder.setLEnum(Tomb.GameTombLogEnum.BATTLE);
                logBuilder.setUserId(dbTombUser.getUserId());
                logBuilder.setActivityId(tombMaze.getActivityId());
                logBuilder.setUnionUid(dbTombUser.getUserInfo().getUnionUid());
                logBuilder.setFloor(dbTombUser.getFloor());
                logBuilder.setX(position.getRow());
                logBuilder.setY(position.getColumn());
                logBuilder.setHp(dbTombUser.getHp());
                logBuilder.setTimestamp(System.currentTimeMillis());
                Tomb.TombLogBattle.Builder battle = Tomb.TombLogBattle.newBuilder();
                battle.setIsPvp(1);
                battle.setAttack(attack);
                battle.setBattleId(pvpDbTombUser.getUserId());
                battle.setRivalMaxHp(pvpDbTombUser.getMaxHp());
                battle.setRivalHp(pvpDbTombUser.getHp());
                battle.setCostEnergy(costEnergy);
                if (isKilled) {
                    battle.setIsKill(1);
                } else {
                    battle.setIsKill(0);
                }
                logBuilder.setBattle(battle);
                Tomb.TombLogMove.Builder logMoveBuilder = Tomb.TombLogMove.newBuilder();
                logMoveBuilder.setEventId(dbTombPosition.getEventId());
                logBuilder.setMove(logMoveBuilder);
                tombMaze.getActivity().sendLogToGame(dbTombUser, logBuilder);

            }
        }

    }


}
